home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple Developer Connection Student Program
/
ADC Tools Sampler CD Disk 3 1999.iso
/
Documentation
/
Books
/
Learn Java on the Macintosh
/
Learn Java Projects
/
09.03 - employee 3
/
Employee3.java
< prev
next >
Wrap
Text File
|
1996-04-22
|
2KB
|
69 lines
/* -------------------------------------------------------------
This applet shows when you might want to use the variable "this".
Java's classes: Applet (applet)
System (lang)
Custom classes: Employee3
Employee
------------------------------------------------------------- */
public class Employee3 extends java.applet.Applet {
Employee e1;
Employee e2;
Employee e3;
public void init() {
e1 = new Employee();
e1.initialize(10, 20);
e2 = new Employee();
e2.initialize(18, 38);
e3 = new Employee();
e3.initialize(12, 52);
}
public void start() {
System.out.println("");
System.out.println("Employee 1:");
e1.displayInfo();
System.out.println("");
System.out.println("Employee 2:");
e2.displayInfo();
System.out.println("");
System.out.println("Employee 3:");
e3.displayInfo();
}
}
class Employee {
int hourlyWage;
int hoursWorked;
int earnedIncome() {
return hourlyWage * hoursWorked;
}
void displayInfo() {
int earnedIncome;
System.out.println("hourly wage = " + hourlyWage);
System.out.println("hours worked = " + hoursWorked);
earnedIncome = earnedIncome();
System.out.println("earned income = " + earnedIncome);
}
void initialize(int hourlyWage, int hoursWorked) {
this.hourlyWage = hourlyWage;
this.hoursWorked = hoursWorked;
}
}